package com.hundsun.s3.platform.staff.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hundsun.s3.common.dto.Client;
import com.hundsun.s3.common.dto.Staff;
import com.hundsun.s3.common.dto.StaffOrder;
import com.hundsun.s3.common.util.BaseDao;
import com.hundsun.s3.staff.service.StaffService;


/**
 * 
 * <p>Title:StaffServiceImpl</p>
 * <p>Description: </p>
 * <p>Company: Hundsun</p>
 * @author :zhangwc23609
 * @date :2018年3月18日 上午11:50:34
 */
@Service
public class StaffServiceImpl extends BaseDao implements StaffService {
	
	//登录
	public Staff login(String staffId, String psw) {
		Map<String, Object> map = new HashMap<>();
		map.put("staff_id", staffId);
		map.put("psw", psw);
		return this.get("500002", map, Staff.class);
	}
	
	//注册
	//注册成功返回1，失败返回0
	public String register(String staffId, String psw, String staffName,
			String sex, String mailBox, String birthday,
			String phoneNumber, String dept_tree, String status) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("staff_id", staffId);
		map.put("psw", psw);
		map.put("staff_name", staffName);
		map.put("sex", sex);
		map.put("mailBox", mailBox);
		map.put("birthday", birthday);
		map.put("phoneNumber", phoneNumber);
		map.put("status", status);
		if(dept_tree == null || dept_tree.equals("") || dept_tree.equals("null")){
			dept_tree = "1";
		}
		map.put("department_id", dept_tree);
		String result = this.exc("500001", map);
		if("执行成功".equals(result)){
			return "1";
		}else{
			return result;
		}
		
	}

	//修改密码
	public String findPwd(String staffId,String psw) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("staff_id", staffId);
		map.put("psw", psw);
		String result = this.exc("500003", map);
		if("执行成功".equals(result)){
			return "1";
		}else{
			return result;
		}
	}
	
	//根据服务人员id获取服务人员信息
	public Staff getStaffById(String staffId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("staff_id", staffId);
		return this.get("500007", map, Staff.class);
	}
	
	//判断服务人员是否存在;1存在，0不存在
	public int judgeStaffId(String staffId) {
		Map<String, Object> map = new HashMap<>();
		map.put("staff_id", staffId);
		String result = this.exc("500008", map);
		return Integer.parseInt(result);
	}
	
	//判断邮箱是否已经注册;1存在，0不存在
	public int judgeMailBox(String mailBox) {
		Map<String, Object> map = new HashMap<>();
		map.put("mailBox", mailBox);
		String result = this.exc("500009", map);
		return Integer.parseInt(result);
	}
	
	//服务人员个人主页---工单信息
	public StaffOrder getStaffOrderById(String staffId) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("staff_id", staffId);
		return this.get("400035", map, StaffOrder.class);
	}
	
	//服务人员修改个人信息
	public String modifyStaffInfo(String staffId, String staffName, String sex,
			String mailBox, String birthday, String phoneNumber, String deptId,
			String status) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("staff_id", staffId);
		map.put("staff_name", staffName);
		map.put("sex", sex);
		map.put("mailBox", mailBox);
		map.put("birthday", birthday);
		map.put("phoneNumber", phoneNumber);
		map.put("status", status);
		map.put("department_id", deptId);
		String result = this.exc("500013", map);
		if("执行成功".equals(result)){
			return "1";
		}else{
			return result;
		}
	}
	
	//修改密码验证
	public Staff selectPsw(String staffId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("staff_id", staffId);
		return this.get("500014", map,Staff.class);
	}
	
	//根据staffid查询客户的用户名和真实姓名
	public List<Client> selClientByStaffId(String staffId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("staff_id", staffId);
		return this.qry("500011", map, Client.class);
	}
	
	
	
}
